using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Tourreau.Gilles.FaxDotNet.Demo
{
    public partial class FaxDataInformations : Form
    {
        public FaxDataInformations()
        {
            InitializeComponent();
        }

        public static FaxJob Send(FaxServer server)
        {
            FaxInformations informations;

            informations = server.GetDefaultInformations();

            using (FaxDataInformations f = new FaxDataInformations())
            {
                f.bindingSourceCoverPage.DataSource = informations.CoverPage;
                f.bindingSourceInformations.DataSource = informations;

                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (f.useCoverPage.Checked == false)
                        informations.CoverPage = null;

                    if (f.printDocumentDemo.Checked == true)
                    {
                        return server.Send(informations, new FaxPrintDocumentDemo());
                    }
                    else
                    {
                        return server.Send(informations, f.fileName.Text);
                    }
                }
            }

            return null;
        }

        public static void Show(FaxInformations informations)
        {
            using (FaxDataInformations f = new FaxDataInformations())
            {
                f.bindingSourceCoverPage.DataSource = informations.CoverPage;
                f.bindingSourceInformations.DataSource = informations;

                f.cancel.Visible = false;
                f.faxInformations.Enabled = false;
                f.coverPageInformations.Enabled = false;
                f.options.Enabled = false;

                f.ShowDialog();
            }
        }

        private void OnFindClick(object sender, EventArgs e)
        {
            if (this.openFileDialog.ShowDialog() == DialogResult.OK)
                this.fileName.Text = this.openFileDialog.FileName;
        }

        private void OnOkClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.recipientNumber.Text) == true)
            {
                FaxMessageBox.Error(FaxResources.NoRecipientNumber);
                this.recipientNumber.Select();
                this.DialogResult = DialogResult.None;
            }
        }

        private void OnUseCoverPageCheckedChanged(object sender, EventArgs e)
        {
            this.coverPageInformations.Enabled = this.useCoverPage.Checked;
            this.coverPageName.Enabled = this.useCoverPage.Checked;
        }

        private void OnPrintDocumentDemoCheckedChanged(object sender, EventArgs e)
        {
            this.fileName.Enabled = !this.printDocumentDemo.Checked;
            this.find.Enabled = !this.printDocumentDemo.Checked;
        }
    }
}